//
//  SEGPgcListModel.m
//  FrameworkTest
//
//  Created by 刘山 on 2018/4/18.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGPgcListModel.h"
#import <objc/runtime.h>


@implementation SEGPgcListModel
+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{@"recommend" : SEGPgcRecommendModel.class};
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
    unsigned int count = 0;
    objc_property_t *propertes = class_copyPropertyList([self class], &count);
    for (int i=0; i<count; i++) {
        const char *propertyName = property_getName(propertes[i]);
        NSString *name = [NSString stringWithUTF8String:propertyName];
        id value = [self valueForKey:name];
        [encoder encodeObject:(value)?value:@"" forKey:name];
    }
}

- (id)initWithCoder:(NSCoder *)decoder
{
    if (self = [super init]) {
        unsigned int count =0;
        objc_property_t *propertes = class_copyPropertyList([self class], &count);
        for (int i = 0; i < count; i++) {
            const char *propertyName = property_getName(propertes[i]);
            NSString *name = [NSString stringWithUTF8String:propertyName];
            id value = [decoder decodeObjectForKey:name];
            [self setValue:(value)?value:@"" forKey:name];
        }
        
    }
    return self;
}

@end
